<script setup>
import { reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus'

const form = reactive({
  msg: '',
  uid: '',
})

onMounted(() => {
  console.log(electronAPI);
  electronAPI.connectNfc()
  electronAPI.onUpdateDeviceMsg((_event, value) => {
    console.log("🚀 ~ window.electronAPI.onUpdateDeviceMsg ~ value:", value)
    form.msg += value
  })
  electronAPI.onUpdateNfcMsg((_event, value) => {
    console.log("🚀 ~ window.electronAPI.onUpdateNfcMsg ~ value:", value)
    let arr = form.uid ? form.uid.split(',') : []
    if (!arr.includes(value)) {
      arr.push(value)
      form.uid = arr.join(',')
    }
  })
})

const handleClick = () => {
  electronAPI.clipboard(form.uid)
  ElMessage({
    showClose: true,
    message: '已复制',
    type: 'success',
  })
}
</script>

<template>
  <el-form :model="form" label-width="auto" label-position="top">
    <el-form-item label="设备信息">
      <el-input v-model="form.msg" type="textarea" readonly :autosize="{ minRows: 4, maxRows: 6 }"
        placeholder="请插入nfc读取设备" />
    </el-form-item>
    <el-form-item label="uid">
      <el-input v-model="form.uid" type="textarea" readonly :autosize="{ minRows: 4 }" />
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="handleClick">复制uid</el-button>
</template>

<style scoped></style>